/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.pneuservis.soap.sei.impl;

import cz.muni.fi.pa165.pneuservis.soap.dto.Transfer;
import cz.muni.fi.pa165.pneuservis.soap.dto.TyreTypeDTO;
import cz.muni.fi.pa165.pneuservis.soap.sei.TyreTypeSEI;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.jws.WebParam;
import javax.jws.WebService;
import pneuservis.backend.services.TyreTypeServiceLocal;
import pneuservis.backend.to.TyreTypeTO;

/**
 *
 * @author Admin
 */
@WebService(endpointInterface="cz.muni.fi.pa165.pneuservis.soap.sei.TyreTypeSEI", serviceName="TyreTypeService")
@Stateless()
public class TyreTypeService implements TyreTypeSEI {
    
    @EJB(lookup="java:global/cz.muni.fi.pa165.pneuservis_Pneuservis-ear_ear_1.0-SNAPSHOT/Pneuservis-ejb-1.0-SNAPSHOT/TyreTypeService")
    TyreTypeServiceLocal tyreTypeService;

    /**
     * Web service operation
     */
    @Override
    public void createTyreType(@WebParam(name = "tyre") TyreTypeDTO tyre) {
        tyreTypeService.createTyreType(Transfer.toTyreTypeTO(tyre));
    }

    /**
     * Web service operation
     */
    @Override
    public void updateTyre(@WebParam(name = "tyre") TyreTypeDTO tyre) {
        tyreTypeService.updateTyreType(Transfer.toTyreTypeTO(tyre));
    }

    /**
     * Web service operation
     */
    @Override
    public void deleteTyre(@WebParam(name = "tyre") TyreTypeDTO tyre) {
        tyreTypeService.removeTyreType(Transfer.toTyreTypeTO(tyre));
    }
    @Override
    public TyreTypeDTO getTyreType(Long id){
        return Transfer.toTyreTypeDTO(tyreTypeService.getTyreType(id));
    }
    @Override
    public TyreTypeDTO[] getAllTyreTypes(){
        List<TyreTypeTO> allTyreTypes = tyreTypeService.getAllTyreTypes();
        return asTyreArray(allTyreTypes);
    }
    @Override
    public TyreTypeDTO[] findTyreTypesByRimSize (int rimSize){
        return asTyreArray(tyreTypeService.findTyreTypesByRimSize(rimSize));
    }
    @Override
    public TyreTypeDTO[] findTyreTypesByWidth(int width){
        return asTyreArray(tyreTypeService.findTyreTypesByWidth(width));
    }
    
    @Override
    public TyreTypeDTO[] findTyreTypesByProfile(int profile){
        return asTyreArray(tyreTypeService.findTyreTypesByProfile(profile));
    }
    
    @Override
    public TyreTypeDTO[] findTyreTypesByManufacturer(String manufacturer){
        return asTyreArray(tyreTypeService.findTyreTypesByManufacturer(manufacturer));
    }
    
    private TyreTypeDTO[] asTyreArray(List<TyreTypeTO> allTyreTypes) {
        List<TyreTypeDTO> result = new ArrayList<>();
        for(TyreTypeTO t : allTyreTypes){
            result.add(Transfer.toTyreTypeDTO(t));
        }
        TyreTypeDTO[] a = new TyreTypeDTO[0];
        return result.toArray(a);
    }
}
